<?php
include 'config.php';

$conn = mysql_connect($HOST, $USER,$PASS) or die(mysql_error());
mysql_select_db($DB) or die('error');
$month = 2;

if ($month == 1) {
  $FROM = '2013-01-01 03:00:00';
  $TO = '2013-02-01 02:59:00';
} else if ($month == 2) {
  $FROM = '2013-02-01 03:00:00';
  $TO = '2013-03-01 02:59:00';
} else  if ($month == 3) {
  $FROM = '2013-03-01 03:00:00';
  $TO = '2013-04-01 02:59:00';
}

echo "----------------------------------\n";
echo "Payment by type \n";
$MERCHANTArr = array('lp000051403449' => 'Vino Santo', 'lpLaVigaRwc' => 'La Viga', 'lpMagdaBg' => 'Magda Luna', 'lpAthertonSubsRwc' => 'Atherton Subs');

$MERCHANTIDArr = array_keys($MERCHANTArr);
foreach ($MERCHANTIDArr as $MERCHANT) {

  echo "For $MERCHANTArr[$MERCHANT], from $FROM to $TO \n";
  $sql = "SELECT PAYMENT, SUM(TOTAL) AS AMT FROM PAYMENTS WHERE MERCHANT_ID = '$MERCHANT' AND CREATEDDATE >'$FROM' AND ".
         " CREATEDDATE < '$TO' GROUP BY PAYMENT";
  $query = mysql_query($sql) or die(mysql_error());
  $k = array();
  while ($row = mysql_fetch_array($query)) {
    $k[] = $row['PAYMENT'].'('.$row['AMT'].') ';  
  }
  echo implode("\n", $k)."\n\n";


}


?>
